package hello_rpc

import (
	"net/rpc"
)

type HelloServiceClient struct {
	*rpc.Client
}

// 估计是为了让HelloServiceClient也实现IHelloService接口，好通过编译器提示必须实现接口
var _ IHelloService = (*HelloServiceClient)(nil)

func DialHelloService(network, address string) (*HelloServiceClient, error) {
	c, err := rpc.Dial(network, address)
	if err != nil {
		return nil, err
	}
	return &HelloServiceClient{Client: c}, nil

	//conn, err := net.Dial(network, address)
	//if err != nil {
	//	return nil, err
	//}
	//c := rpc.NewClientWithCodec(jsonrpc.NewClientCodec(conn))
	//return &HelloServiceClient{Client: c}, nil
}

func (c *HelloServiceClient) Hello(req string, reply *string) error {
	return c.Client.Call(HelloServiceName+".Hello", req, reply)
}
